import { URL_KLINE_HISTORY, URL_SIGNAL_LIST } from "@/comm/api";
import { formatKey, formatTimeAgo, formatTimestamp } from "@/comm/format";
import { get } from "@/comm/request";
import { uuidCreate } from "@/comm/uuid";
import { defineStore } from "pinia";

interface IState {
    list: Array<any>;
    show: boolean;
}

export const useSignal = defineStore("signal", {
    state: (): IState => ({
        list: [] as any[],
        show: true
    }),

    getters: {
        visibleRange(state) {
            return state.list;
        }
    },
    actions: {
        async loadHistory(symbol: string, interval: string) {
            this.list = [];
            let res: any = await get(URL_SIGNAL_LIST, {
                symbol: symbol,
                interval: interval
            });
            this.list = res.data || [];
            this.list.forEach(i => {
                i.date = formatTimestamp(i.timestamp);
            });

            return;
        },
        changeShow(val: boolean) {
            this.show = val;
        },
        addItem(val: any) {
            this.list.push(val);
        }
    }
});
